<template>
	<view class="content">
		<u-navbar title="天商" placeholder leftIcon="">
			<view class="flexright xiaohui" style="font-size: 30rpx;color: #ff0000;" slot="right" @click="goAddGoods">点此添加</view>
		</u-navbar>
		<u-sticky>
			<!-- 搜索框 -->
			<!-- <view class="header ffffff paddinglr" :style="{paddingTop:systemBarHeight+'rpx'}">
				<view class="searchBox">
					<u-icon name="search" color="rgba(202, 202, 202, 1)" size="22"></u-icon>
					<input class="searchInput" placeholder-class="searchPlaceholder" type="text" placeholder="搜索关键字"
						confirm-type="search" @confirm="init()" v-model="keyword">
				</view>
			</view> -->
			<view class="ffffff paddinglr" style="margin-left: -15rpx;">
				<u-tabs :list="tabList" @click="change" lineColor="rgba(243, 39, 28, 1)" :activeStyle="{
			    color: '#000000',
			    fontWeight: 800,
			    transform: 'scale(1.05)'}" :inactiveStyle="{
			    color: '#666666',
			    transform: 'scale(1)'
			}"></u-tabs>
			</view>
		</u-sticky>
		<!-- tab内容 -->
		<view class="backFA padding">
			<view class="teacherBox" v-for="(item,index) in list.data" :key="item.id">
				<view class="flexleft">
					<view class="left">
						<image :src="item.image_text" mode=""></image>
					</view>
					<view class="right" style="height: 140rpx;">
						<view class="name">{{item.name}}</view>
						<!-- <view class="color_san text_five margin_top1 margin_bottom1">60/升级版</view> -->
						<view class="flexbetween">
							<view class="price">￥{{item.price}}</view>
						</view>
					</view>
				</view>
				<view class="padding flexbetween margin_top">
					<view class="flexleft" @click="edit('/pages_business/addGoods?id=',item.id)">
						<image class="imgEdit margin_right1" src="/static/image/mine/edit.png" mode=""></image>
						<view class="color_ling text_a">编辑</view>
					</view>
					<view class="flexleft" @click="updown(item)">
						<!-- <image class="imgSelf margin_right1" src="/static/image/home/shelf.png" mode=""></image> -->
						<image class="imgSelf margin_right1" src="/static/image/home/shelf_top.png" mode="">
						</image>
						<view class="color_ling text_a">{{item.status=='hidden'?"已下架":"已上架"}}</view>
					</view>
					<view class="flexleft" @click="del(item)">
						<image class="imgDelete margin_right1" src="/static/image/mine/delete.png" mode="">
						</image>
						<view class="color_ling text_a">删除</view>
					</view>
					<view class="flexleft" @click="goAllEval(item.id)">
						<image class="imgComm margin_right1" src="/static/image/home/comment.png" mode="">
						</image>
						<view class="color_ling text_a">评价</view>
					</view>
				</view>
			</view>
			<view class="flexcenter placeholderBoxTop" v-if="!list.data.length">
				<image class="placeholderBox" src="/static/placeholderimg.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				tabActive: 0,
				tabList: [],
				systemBarHeight: "",
				category_id: "",
				page: 1,
				list: {
					data: []
				},
				keyword: "",
				isLoad: false,
			}
		},
		watch: {
			tabActive() {
				this.active = 0
			}
		},
		onLoad() {
			this.systemBarHeight = getApp().globalData.systemBarHeight * 2 + 40
			this.getHomeInit()
		},
		onShow() {
			if (this.isLoad) {
				// console.log("onShow")
				this.init()
			}
		},
		methods: {
			init(isPage, page) {
				let _this = this;
				let category_id = this.category_id
				httpRequest.request('/api/shop.goods/getlist', 'GET', {
					page: page || 1,
					category_id,
					keyword: this.keyword
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// 编辑
			edit(url, val) {
				uni.navigateTo({
					url: url + val
				})
			},
			// 删除服务
			del(item) {
				httpRequest.modal('提示', '请再次确认', true, (res) => {
					if (res) {
						httpRequest.request('/api/shop.goods/del', 'POST', {
							id: item.id,
						}).then(res => {
							httpRequest.toast(res.msg)
							if (res.code == 1) {
								this.init()
							}
						})
					}
				})
			},
			// 上下架
			updown(item) {
				httpRequest.modal('提示', '请再次确认', true, (res) => {
					if (res) {
						httpRequest.request('/api/shop.goods/updown', 'POST', {
							id: item.id,
						}).then(res => {

							if (res.code == 1) {
								if (item.status == "normal") {
									httpRequest.toast("下架成功")
								} else {
									httpRequest.toast("上架成功")
								}
								this.init()
							} else {
								httpRequest.toast(res.msg)
							}
						})
					}
				})
			},
			// 获取首页数据
			getHomeInit() {
				httpRequest.request("/api/shop.goods/getform", "GET", {}).then(res => {
					this.tabList = res.data.goods_category
					// this.category_id = res.data.goods_category[0].id
					this.tabList.unshift({
						name: "全部",
						id: "",
					})
					this.isLoad = true
					this.init()
				})
			},
			change(e) { //tab栏切换
				this.tabActive = e.index
				this.category_id = e.id
				this.init()
			},
			goAddGoods() { //添加商品
				uni.navigateTo({
					url: "/pages_business/addGoods"
				})
			},
			// goVideoInfo() { //视频详情
			// 	uni.navigateTo({
			// 		url: "/pages_index/videoInfo"
			// 	})
			// },
			goAllEval(id) { //评价
				uni.navigateTo({
					url: "/pages_service/allEval?type=1&id="+id
				})
			},
			// goSearch() { //搜索商品
			// 	uni.navigateTo({
			// 		url: "/pages/index/search"
			// 	})
			// }
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding-bottom: 100rpx;
	}

	::v-deep.u-tabs__wrapper__nav__item {
		flex: 1 !important;
		white-space: nowrap;
	}

	// tab栏
	.tab1 {
		width: 44rpx;
		height: 41rpx;
	}

	.tab2 {
		width: 41.58rpx;
		height: 41.58rpx;
	}

	.tab3 {
		width: 42.12rpx;
		height: 36.85rpx;
		margin-top: 5rpx;
		margin-bottom: 5rpx;
	}

	.tab4 {
		width: 42rpx;
		height: 42rpx;
	}

	// tab结束
	.imgJia {
		width: 36rpx;
		height: 36rpx;
	}

	.backFA {
		background-color: #FAFAFA;
	}

	// 搜索框
	.header {
		// margin-top: 96rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.searchBox {
		padding: 18rpx 30rpx;
		background: #F3F3F3;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
		display: flex;
		align-items: center;
		flex: 1;

		.searchInput {
			margin-left: 20rpx;
			font-size: 24rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
		}

		.searchPlaceholder {
			font-size: 24rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #C5C5C5;
		}
	}

	// 导航栏
	.scroll-view_H {
		white-space: nowrap;
		width: 100%;
	}

	.weixuanzhong {
		padding: 10rpx 35rpx;
		background: #EFEFEF;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 1rpx solid #EFEFEF;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.xuanzhong {
		padding: 10rpx 35rpx;
		background: rgba(243, 39, 28, 0.1);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 1rpx solid #F3271C;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #F3271C;
	}

	// 天问
	.teacherBox {
		background-color: #ffffff;
		padding: 36rpx 15rpx 36rpx 30rpx;
		margin-bottom: 30rpx;
		// display: flex;

		.left {
			width: 140rpx;
			height: 140rpx;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			margin-right: 30rpx;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.right {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			flex: 1;

			.name {
				font-size: 30rpx;
				font-family: PingFang SC-Heavy, PingFang SC;
				font-weight: 500;
				color: #333333;
			}

			.price {
				font-size: 28rpx;
				font-family: PingFang SC-Heavy, PingFang SC;
				font-weight: 800;
				color: #F3271C;
			}
		}

		.imgEdit {
			width: 18.67rpx;
			height: 24.27rpx;
			display: block;
		}

		.imgSelf {
			width: 21rpx;
			height: 21.84rpx;
			display: block;
		}

		.imgDelete {
			width: 23.33rpx;
			height: 24.27rpx;
			display: block;
		}

		.imgComm {
			width: 28rpx;
			height: 28rpx;
			display: block;
		}
	}
</style>